<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link rel="stylesheet" href="./swiper-5.4.5/css/swiper.css" />
    <style>
      .swiper-container {
        width: 600px;
        height: 300px;
      }
    </style>
    <script src="./swiper-5.4.5/js/swiper.js"></script>
    <script src="./js/template-web.js"></script>
  </head>
  <body>
    <div class="swiper-container">
      <div class="swiper-wrapper">
        <!-- <div class="swiper-slide">Slide 1</div>
        <div class="swiper-slide">Slide 2</div>
        <div class="swiper-slide">Slide 3</div> -->
      </div>
      <!-- 如果需要分页器 -->
      <div class="swiper-pagination"></div>

      <!-- 如果需要导航按钮 -->
      <div class="swiper-button-prev"></div>
      <div class="swiper-button-next"></div>
    </div>
    <script type="text/html" id="slides">
     {{each }}
    </script>
    <script>
      fetch('http://www.liulongbin.top:3005/api/getlunbo')
        .then((res) => res.json())
        .then((res) => {
          // console.log(res, 111)
          /* var str = '';
          for (let i = 0; i < res.message.length; i++) {
            let item = res.message[i];
            str += `<div class="swiper-slide"><img src="${item.img}" /></div>`;
          }
          document.querySelector('.swiper-wrapper').innerHTML = str; */
          var htmlStr = template('slides', res.message)
          $('.swiper-wrapper').html(htmlStr)
          var mySwiper = new Swiper('.swiper-container', {
            // direction: 'vertical', // 垂直切换选项
            loop: true, // 循环模式选项
            // 如果需要前进后退按钮
            navigation: {
              nextEl: '.swiper-button-next',
              prevEl: '.swiper-button-prev',
            },
          });
        });
    </script>
  </body>
</html>
